<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <title> - 注册</title>
    <meta name="keywords" content="">
    <meta name="description" content="">

    <link rel="shortcut icon" href="favicon.ico">
    <link href="css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="css/custom.css" rel="stylesheet">
    <link href="css/animate.css" rel="stylesheet">
    <link href="css/style.css?v=4.1.0" rel="stylesheet">
    <script>if (window.top !== window.self) {
        window.top.location = window.location;
    }</script>

</head>

<body class="gray-bg">

<div class="middle-box text-center loginscreen   animated fadeInDown">
    <div>
        <div>

            <h1 class="logo-name"></h1>
            <img class="logo-name" src="img/logoh.png" height="280px" width="280px"/>
        </div>
        <br/>
        <h3>注册 </h3>
        <p>创建一个A市人民医院新账户</p>
        <form class="m-t" role="form" action="login.html">
            <div class="form-group">
                <input type="text" id="name" class="form-control" placeholder="请输入姓名" required="">
            </div>
            <div class="form-group">
                <input type="text" id="card" class="form-control" placeholder="请输入身份证号" required="">
            </div>
            <div class="form-group">
                <input type="text" id="phone" class="form-control" placeholder="请输入手机号" required="">
            </div>
            <div class="form-group">
                <input type="number" id="age" class="form-control" placeholder="请输入年龄" required="">
            </div>
            <div class="form-group">
                <div class="form-group">
                    <select class="form-control" id="sex">
                        <option>请选择性别</option>
                        <option value="0">男</option>
                        <option value="1">女</option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <input type="password" id="password" class="form-control" placeholder="请输入密码" required="">
            </div>
            <div class="form-group">
                <input type="password" id="rePassword" class="form-control" placeholder="请再次输入密码" required="">
            </div>
            <div class="form-group text-left">
                <div class="checkbox i-checks">
                    <label class="no-padding">
                        <input type="checkbox" id="checkboxBut"><i></i> 我同意注册协议</label>
                </div>
            </div>
            <button type="button" id="submit" onclick="register()" class="btn btn-primary block full-width m-b">注 册
            </button>

            <p class="text-muted text-center"><small>已经有账户了？</small><a href="login.html">点此登录</a>
            </p>

        </form>
    </div>
</div>

<!-- 全局js -->
<script src="js/jquery.min.js?v=2.1.4"></script>
<script src="js/bootstrap.min.js?v=3.3.6"></script>
<!-- iCheck -->
<!--<script src="js/plugins/iCheck/icheck.min.js"></script>-->
<script src="./js/index.js"></script>
<script>
    // $(document).ready(function () {
    //     $('.i-checks').iCheck({
    //         checkboxClass: 'icheckbox_square-green',
    //         radioClass: 'iradio_square-green',
    //     });
    // });


    function register() {
        if ($("#checkboxBut").get(0).checked) {
            var name = $("#name").val().trim();
            var password = $("#password").val().trim();
            var rePassword = $("#rePassword").val().trim();
            var card = $("#card").val().trim();
            var sex = $("#sex").val().trim();
            var age = $("#age").val().trim();
            var numAge = parseInt(age);
            var phone = $("#phone").val().trim();
            if (name == null) {
                alert("请输入名字！");
                return false;
            }
            if (phone == null || phone.length != 11) {
                alert("手机号不符合规范！");
                return false;
            }
            if (card == null || card.length != 18) {
                alert("身份证不符合规范！");
                return false;
            }
            if (rePassword == null || password == null || rePassword != password) {
                alert("两次密码不一致！");
                return false;
            }
            if (sex == null || (sex != 0 && sex != 1)) {
                alert("请输入性别！");
                return false;
            }
            if (age != null) {
                if (numAge < 0 && numAge >= 150) {
                    alert("请输入正确年龄！");
                    return false;
                }
            } else {
                alert("请输入年龄！");
                return false;
            }
            $.ajax({
                async: true,
                type: "post",
                url: "/register",
                data: JSON.stringify(getQueryData()),
                contentType: 'application/json',
                dataType: "text",
                success: function (data) {
                    var result = JSON.parse(data);
                    console.log(result);
                    if (result.SUCCESS) {
                        alert(result.RESULT);
                        window.location.href = "/index.html";
                    } else {
                        alert(result.RESULT);
                    }
                },
                error: function (data) {
                    alert("请求失败");
                }
            });
        } else {
            alert("请同意注册协议！")
            return false;
        }
    }


    function getQueryData() {
        var dto = {};
        if (!ifEmpty($("#name").val())) {
            dto["name"] = $("#name").val().trim();
        }
        if (!ifEmpty($("#card").val())) {
            dto["card"] = $("#card").val().trim();
        }
        if (!ifEmpty($("#phone").val())) {
            dto["phone"] = $("#phone").val().trim();
        }
        if (!ifEmpty($("#age").val())) {
            dto["age"] = $("#age").val().trim();
        }
        if (!ifEmpty($("#sex").val())) {
            dto["sex"] = $("#sex").val().trim();
        }
        if (!ifEmpty($("#password").val())) {
            dto["password"] = $("#password").val().trim();
        }
        return dto;
    }


</script>


</body>

</html>
